<template>
	<view class="ratestyle">
		 <view class="" style="text-align: center; margin-top: 35%;  font-size: 40upx;">请给对方此次进行评分</view>
		 <view class="fatherstyle">
			  <uni-rate class="ratesty" size="40" margin="10" v-model="value" @change="onChange"/>
		 </view>
		<button  class="butRate" @click="rateVlu"  >提交</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value:3,//评分数字
				eventId:'',//事件id
			}
		},
		onLoad(option) {	
			console.log(option.eventId); //打印出上个页面传递的参数。
			this.eventId = option.eventId;
		},
		methods: {
			//提交具体评分
			rateVlu(){
				console.log(this.value)
				//将评分给服务器
				  var userInfo = uni.getStorageSync('globalUser');
				  // if(userInfo !== null && userInfo !== "" && userInfo !== undefined){
				  // 	userId = userInfo._id;
				  // }else{
				  // 	userId = ''; //清空数据
				  // }
				 
				  //老人对志愿者评分
				  if(userInfo.userType == "0"){
					  console.log("old");
					uniCloud.callFunction({
					    name:"subRate",
						data:{
							type:0,//老人给志愿者评分
							eventId:this.eventId,
							rateValu:this.value
						},
						success: (res) => {
							uni.showToast({
								title: '评价成功',
								duration:3000
							});
							console.log(res);
						}
					});  
					  
				  }else{
					 //志愿者对老人的评分
					 console.log("volun");
					 
					 uniCloud.callFunction({
					     name:"subRate",
					 	data:{
							type:1,//志愿者给老人评分
					 		eventId:this.eventId,
							rateValu:this.value
					 	},
					 	success: (res) => {
					 		uni.showToast({
					 			title: '评价成功',
					 			duration:3000
					 		});
							
							uni.switchTab({
							    url: '/pages/index/index'
							});
							console.log(res);
					 	}
					 });	
					 
				  }
				 
			},
			//评分改变
			onChange(e) {
			    console.log('rate发生改变:' + JSON.stringify(e))
			        }
		}
	}
</script>

<style>
 .fatherstyle{
	display: flex;
	justify-content: center;
	align-items: center;
	  height: 200upx;
	  width: 80%;
	  background-color: #f6f6f6;
	  margin-top: 60upx;
	  margin-bottom: 100upx;
  }

	.butRate{
		background-color: #f5da3f;
		border:1px solid #f5da3f;
		color: #FFFFFF;
		font-size: 40upx;
		 width: 70%;
		 height: 100upx;
		line-height: 100upx;
	    border-radius: 25px;
	} 
	.ratestyle{
		display: flex;	
		flex-direction: column;
		align-items: center;
	}
</style>
